/**
 *  @author Conrelius Huang
 *  opp dmd matrix form backend
 */
app.factory('bkMatrixService', ['$q', '$http', function($q, $http) {
	var baseUrl = '/DRMS/api';
	return function(oppStatus) {
		if(oppStatus == undefined) {
			oppStatus = {
					statusId: 0,
					statusName: null
				}
		} else if(oppStatus.statusName === 'None') {
			oppStatus = {
					statusId: 0,
					statusName: null
				}
		}
		return $q(function(resolve, reject) {
			$http({
				url: baseUrl + '/oppdmdmatrix/get',
				method: 'POST',
				headers: {
					'Content-Type': 'application/json'
				},
				data: oppStatus
			}).then(function(response) {
				resolve(response.data);
			}, function(response) {
				reject('bkMatrixService - reject');
			})
		});
	}
}]);

app.factory('dmdStatusSelectService', ['$q', '$http', function($q, $http) {
	var baseUrl = '/DRMS/api';
	return function(oppId, dmdstatus) {
		if(dmdstatus == undefined) {
			dmdstatus = {
				dmdStatusId: 0,
				dmdStatusName: null
			}
		} else if(dmdstatus.dmdStatusName === 'Active') {
			dmdstatus = {
				dmdStatusId: 0,
				dmdStatusName: null
			}
		}
		return $q(function(resolve, reject) {
			$http({
				url: baseUrl + '/oppdmdmatrix/findDemand',
				method: 'POST',
				headers: {
					'Content-Type': 'application/json'
				},
				data: {
					oppId: oppId,
					demandStatus: dmdstatus
				}
			}).then(function(response) {
				resolve(response.data);
			}, function() {
				reject('dmdStatusSelectService - reject');
			})
		});
	}
}]);

app.factory('tsuikaService', ['$http', '$q', function($http, $q) {
	var baseUrl = '/DRMS/api';
	return {
		getResult: function(showId) {
			return $q(function(resolve, reject) {
				$http({
					url: baseUrl + '/demandrequest/getDrmsDemandRequestByshouID?showId=' + showId,
					method: 'GET'
				}).then(function(response) {
					resolve(response.data);
				}, function() {
					reject(undefined);
				})
			})
		}
	}
}]);